#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{
    int age;
    struct Node *next;
} Node;

// 双指针传参
void test(Node **p)
{

    printf("test:\n");
    printf("数据: p.age = %d\n", (*p)->age);
    printf("地址:p = %x, (*p) = %x, (*p)->next = %x\n", p, (*p), (*p)->next);
    printf("指针p的地址 = %x\n\n", &p);

    // 在函数内定义一个新的结构体
    Node q;
    q.age = 3;
    q.next = NULL;

    // 为结构体(*p)重新分配地址，并修改变量数据
    (*p) = (Node *)malloc(sizeof(Node));
    (*p)->age = 2;
    (*p)->next = &q;

    printf("数据: p.age = %d\n", (*p)->age);
    printf("地址:p = %x, (*p) = %x, (*p)->next = %x\n", p, (*p), (*p)->next);
    printf("指针p的地址 = %x\n\n", &p);

    printf("数据: q.age = %d\n", q.age);
    printf("地址: q = %x, q->next = %x\n\n", &q, q.next);
}

int main()
{

    Node *p;
    // 为指针结构体p分配地址
    p = (Node *)malloc(sizeof(Node));
    p->age = 1;
    p->next = NULL;

    printf("main():\n");
    printf("数据: p.age = %d\n", p->age);
    printf("地址: p = %x, p->next = %x\n", p, p->next);
    printf("指针p的地址 = %x\n\n", &p);

    test(&p);

    printf("main():\n");
    printf("数据: p.age = %d\n", p->age);
    printf("地址: p = %x, p->next = %x\n", p, p->next);
    printf("指针p的地址 = %x\n\n", &p);

    return 0;
}
